package com.perceptivesoftware.licensing.dao;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.springframework.stereotype.Repository;
import com.perceptivesoftware.licensing.dao.generated.TwRolevalDAO;
import com.perceptivesoftware.licensing.domain.generated.TwRoleval;
import com.perceptivesoftware.licensing.domain.generated.TwUserval;

@Repository
public class TwRolevalDaoExt extends TwRolevalDAO
{

	public List<TwRoleval> getNotDeletedRolevals()
	{
		final ArrayList<TwRoleval> ret = new ArrayList<TwRoleval>();
		for (final TwRoleval role : findAll())
		{
			final String deleted = role.getRolevalDeleted();
			if (deleted == null || deleted.length() == 0) // modified to exclude
															// "P"
			{
				ret.add(role);
			}
		}
		return ret;
	}

	public TwRoleval update(final TwRoleval entity, final TwUserval modifyingUser)
	{
		entity.setRolevalDateModified(new Timestamp((new Date()).getTime()));
		entity.setTwUservalByRolevalModifiedBy(modifyingUser);
		return update(entity);
	}

	public void save(final TwRoleval entity, final TwUserval creatingUser)
	{
		entity.setRolevalDateCreated(new Timestamp((new Date()).getTime()));
		entity.setTwUservalByRolevalCreatedBy(creatingUser);
		update(entity);
	}
}
